package com.zzyl.service.impl;

/**
 * @Description NursingProjectImpl
 * @Author jack
 * @Date 2024-08-25
 */

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description NursingProjectVoServiceImpl
 * @Author liuzhiwei
 * @Date 2024-08-23
 */



@Service
@Slf4j
public class NursingProjectVoServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 改变启用禁用
     *
     * @param id
     * @param status
     */
    @Override
    public void status(Long id, int status) {
        if (status==1){
            status=0;
        }else {
            status=1;
        }
        NursingProjectMapper.status(id,status);
    }

    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
//        log.info("服务层 - 分页查询护理项目列表 - 参数: name={}, status={}, pageSize={}, pageNum={}", name, status, pageSize, pageNum);

        //1.设置pageHelper.startPage页码和每页显示多少条
        PageHelper.startPage(pageNum, pageSize);
        //2.执行数据库查询列表数据
        Page<NursingProjectVo> page = nursingProjectMapper.selectByPage(name, status);

        //3.封装PageResponse
        PageResponse<NursingProjectVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
//        log.info("服务层 - 分页查询护理项目列表 - 结果: {}", pageResponse);
        return pageResponse;
    }

    /**
     * 新增项目
     * @param nursingProjectDto
     */
    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject=new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.add(nursingProject);
        return ;
    }

    /**
     * 根据id删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public NursingProjectVo select(Long id) {
        NursingProjectVo nursingProjectVo=nursingProjectMapper.select(id);
        return nursingProjectVo;
    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        nursingProjectMapper.update(nursingProjectDto);
    }
/**
     * 新增
     * @param nursingProjectDto
     */
}
